#!/usr/bin/env ruby

require 'CompositeSOA'

PATHSVN = "https://svn.dtvops.net/dev/projects/contentManagement/contentServices/CS"
PATHLOCAL = "/home/vkorzh75/JDeveloper/mywork/CS"
PATHMASK = "/**/trunk"
COMPOSITEMASK = "/**/composite.xml"
  
class CompositeGroup
  attr_accessor :path, :path_mask, :filter, :info
  
  def initialize(path = nil, path_mask = nil)
    if path.to_s != ""
      @path = path
    else
      @path = PATHLOCAL
    end
    if path_mask.to_s != ""
      @path_mask = path_mask.to_s
    else
      @path_mask = PATHMASK
    end
    @path + @path_mask
  end

  def isApp?
    info != nil and info.size > 0
  end

  def info
    Hash[all.collect{|a| [a.name,a]}]
  end

  def all
    Dir[File.join(path_local, path_mask, COMPOSITEMASK)].collect{|a| c=CompositeSOA.new(a)}
  end

  def composite(id = nil)
    comp = info[id] if !id.nil?
    comp = all[id.to_i] if !id.nil? and comp.nil?
    comp
  end
  
  def to_s
    info.to_s
  end

  def path_local
    Svn.path_local(path)
  end

end